package com.imti.roomdemo;

import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.util.List;

public class MainActivity extends AppCompatActivity
{

    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
    }

    private void initData()
    {
        StuEntity stu = new StuEntity();
        stu.stuName = "张三";
        stu.stuAge = 20;
        stu.stuGender = "男";

        //ROOM框架下的所有DAO操作必须在子线程中完成
        new Thread()
        {
            @Override
            public void run()
            {
                super.run();
//                DBHelper.getInstance(MainActivity.this)
//                    .getDB().stuDAO().insertStu(stu);

                List<StuEntity> result =
                    DBHelper.getInstance(MainActivity.this)
                        .getDB().stuDAO().queryAll();
                for (int i = 0; i < result.size(); i++)
                {
                    Log.d(TAG, "姓名：" + result.get(i).stuName);
                    Log.d(TAG, "性别：" + result.get(i).stuGender);
                    Log.d(TAG, "年龄：" + result.get(i).stuAge);
                }
            }
        }.start();
    }
}